
public class Stack
{
    
    private String[] data;
    private int headIndex = -1;

    public static void main(String[] args) {
        Stack stack = new Stack(10);
        
        stack.push("1");
        stack.push("2");
        stack.push("3");
        stack.push("4");
        stack.push("5");
        stack.push("6");
        stack.push("7");
        stack.push("8");
        stack.push("9");
        stack.push("10");
        stack.push("11");
        
        System.out.println("peek: " + stack.peek());
        System.out.println("pop: " + stack.pop());
        System.out.println("pop: " + stack.pop());
        System.out.println("pop: " + stack.pop());
        System.out.println("peek: " + stack.peek());
        
    }
    
    public Stack(int size) {
        data = new String[size];
    }
    
    private void push(String item) {
        int nextIndex = headIndex + 1;
        
        if(nextIndex < data.length) {
            data[nextIndex] = item;
            headIndex = nextIndex;
        } else {
            System.out.println("Stack is full, need to grow it.");
        }
    }
    
    private String pop() {
        if(headIndex == -1) {
            return null;
        } else {
            int currentIndex = headIndex;
            --headIndex;
            return data[currentIndex];
        }
    }
    
    private String peek() {
        if(headIndex == -1) {
            return null;
        } else {
            return data[headIndex];
        }
    }

}
